<template>
    <div id="layout">
      <el-container id="con">
        <el-aside width="400px" >
            <div id="patient-form">
              <el-form ref="form" :model="pformdata" label-width="80px">
                <el-form-item label-width="68px" label="患者姓名">
                    <el-input size="mini" style="margin-left: 10px;width: 170px"  class="input-width" disabled v-model="pformdata.patientName"></el-input>
                  <el-button size="mini" icon="el-icon-user-solid" @click="selectPatients"></el-button>
                </el-form-item>
                <el-form-item label-width="68px" label="身份证号">
                  <el-input size="mini" class="input-width" disabled v-model="pformdata.patientCard"></el-input>
                </el-form-item>
                <el-form-item label-width="68px"  label="患者电话">
                  <el-input size="mini" class="input-width" disabled v-model="pformdata.patientPhone"></el-input>
                </el-form-item>

                <el-form-item label-width="68px" label="性别">
                  <el-radio-group size="mini" class="input-width" v-model="pformdata.patientSex">
                    <el-radio  value="2" label="2">男</el-radio>
                    <el-radio  value="1" label="1">女</el-radio>
                    <el-radio  value="0" label="0">未知</el-radio>
                  </el-radio-group>
                </el-form-item>


                <el-form-item label-width="68px"  label="出生日期">
                  <el-date-picker
                    v-model="pformdata.patientBirthday"
                    type="date"
                    style="width: 200px"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>

                <el-form-item label-width="68px"  label="患者年龄">
                  <el-input size="mini" class="input-width" v-model="pformdata.patientAge"></el-input>
                </el-form-item>
                <el-form-item label-width="68px" label="地址信息">
                  <el-input size="mini" class="input-width" autosize maxlength="30" show-word-limit type="textarea" v-model="pformdata.patientAddress"></el-input>
                </el-form-item>

                <el-form-item label-width="68px" label="过敏史">
                  <el-input size="mini" class="input-width" autosize maxlength="100" show-word-limit type="textarea" v-model="pformdata.patientAllergy"></el-input>
                </el-form-item>

              </el-form>
              <div>
                <el-tabs v-model="activeTabName" type="card" @tab-click="handleInfoClick">
                  <el-tab-pane label="患者档案" name="first">暂无患者档案</el-tab-pane>
                  <el-tab-pane label="历史病例" name="second" v-if="tableCaseData == ''">暂无历史病例</el-tab-pane>
                  <el-tab-pane label="历史病例" name="second" v-else-if="tableCaseData != '' && tableCaseData.length > 0">
                    <el-table
                      ref="singleTable"
                      :data="tableCaseData"
                      highlight-current-row
                      @current-change="handleCurrentChange"
                      style="width: 100%">
                      <el-table-column
                        type="index"
                        width="20">
                      </el-table-column>
                      <el-table-column
                        property="caseId"
                        label="病例编号"
                        >
                      </el-table-column>
                      <el-table-column
                        property="createTime"
                        label="诊断日期"
                        >
                      </el-table-column>
                      <el-table-column
                        property="doctorName"
                        label="医生">
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                </el-tabs>
              </div>
            </div>
        </el-aside>
        <el-container>
          <!--设置头部位置-->
          <el-header height="100px">
            <div id="title-header" style="text-align: left;line-height: normal">
              <div style="float: right;margin: 0px">
                <el-button type="primary" icon="el-icon-check" @click="saveCase">保存病例</el-button>
                <el-button type="danger" icon="el-icon-check" @click="finshcase">接诊完成</el-button>
              </div>
              挂号单ID:<span style="color: red" v-if="this.pformdata.registerId != null && this.pformdata.registerId != ''">{{this.pformdata.registerId}}</span>
              <span style="color: red" v-else="this.pformdata.patientId == null || this.pformdata.patientId == ''">选择患者后显示</span>
              <br>
              病例编号:<span style="color: red" v-if="this.queryParams.caseId != null && this.queryParams.caseId != ''">{{this.queryParams.caseId}}</span>
              <span style="color: red" v-else="this.pformdata.patientId == null || this.pformdata.patientId == ''">保存病例后生成</span>
            </div>

          </el-header>
          <el-main style="line-height: normal">
              <div id="case-main">
                <el-tabs v-model="activeName" type="card" >
                  <el-tab-pane label="病例" name="first">
                    <el-form ref="form" :inline="true" :model="queryParams" label-width="68px" size="mini">
                      <el-form-item label="发病日期">
                        <el-date-picker
                          v-model="queryParams.caseDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择日期">
                        </el-date-picker>
                      </el-form-item>

                      <el-form-item label="接诊类型">
                        <el-select v-model="queryParams.caseType" placeholder="请选择接诊类型">
                          <el-option label="初诊" value="1"></el-option>
                          <el-option label="复诊" value="2"></el-option>
                        </el-select>
                      </el-form-item>

                      <el-form-item label="是否传染">
                        <el-select v-model="queryParams.caseIsfect" placeholder="请选择是否传染">
                          <el-option label="是" value="1"></el-option>
                          <el-option label="否" value="0"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-form>
                    <el-form ref="form" :model="queryParams" label-width="68px" size="medium" style="margin-right: 30px">
                        <el-form-item label="主诉" >
                          <el-input
                            type="textarea"
                            :rows="3"
                            placeholder="请输入内容"
                            maxlength="200" show-word-limit
                            v-model="queryParams.caseMainsay">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="诊断信息">
                          <el-input
                            type="textarea"
                            :rows="3"
                            placeholder="请输入内容"
                            maxlength="200" show-word-limit
                            v-model="queryParams.caseDiagInfo">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="医生建议">
                          <el-input
                            type="textarea"
                            :rows="3"
                            placeholder="请输入内容"
                            maxlength="200" show-word-limit
                            v-model="queryParams.caseAdvice">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="备注">
                          <el-input
                            type="textarea"
                            :rows="3"
                            placeholder="请输入内容"
                            maxlength="200" show-word-limit
                            v-model="queryParams.caseRemark">
                          </el-input>
                        </el-form-item>
                    </el-form>
                  </el-tab-pane>
                  <el-tab-pane label="处方" name="second">
                      <div>
                        <el-button type="success" icon="el-icon-plus" @click="centerDialogVisible = true">添加药用处方</el-button>
                        <el-button type="success" icon="el-icon-plus" @click="centerCheckDialogVisible = true">添加检查处方</el-button>
                      </div>
                  </el-tab-pane>
                </el-tabs>
              </div>
          </el-main>
        </el-container>
      </el-container>
      <div id="dialog-form">
          <el-dialog title="选择挂号患者" center :visible.sync="dialogTableVisible">
            <el-tabs type="border-card" @tab-click="handleReceptionClick">
              <el-tab-pane label="待就诊列表">
                <div id="show-data">
                  <el-table
                    :data="tableData"
                    style="width: 100%">
                    <el-table-column type="expand">
                      <template slot-scope="props">
                        <el-form label-position="left" inline class="demo-table-expand">
                          <el-form-item label="患者姓名:">
                            <span>{{ props.row.kbjzPatient.patientName }}</span>
                          </el-form-item>
                          <el-form-item label="患者电话:">
                            <span>{{ props.row.kbjzPatient.patientPhone }}</span>
                          </el-form-item>
                          <el-form-item label="患者编号:">
                            <span>{{ props.row.kbjzPatient.patientId }}</span>
                          </el-form-item>
                          <el-form-item label="患者性别:">
                            <span>{{ props.row.kbjzPatient.patientSex }}</span>
                          </el-form-item>
                          <el-form-item label="患者年龄:">
                            <span>{{ props.row.kbjzPatient.patientAge }}</span>
                          </el-form-item>
                          <el-form-item label="地址信息:">
                            <span>{{ props.row.kbjzPatient.patientAddress }}</span>
                          </el-form-item>
                          <el-form-item label="过敏史:">
                            <span>{{ props.row.kbjzPatient.patientAllergy }}</span>
                          </el-form-item>
                        </el-form>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="患者姓名"
                      prop="kbjzPatient.patientName">
                    </el-table-column>

                    <el-table-column
                      label="流水编号"
                      prop="pipeNum">
                    </el-table-column>

                    <el-table-column
                      label="挂号类型"
                      prop="sysRegFee.rfeeName">
                    </el-table-column>

                    <el-table-column label="操作">
                      <template slot-scope="scope">
                        <el-button
                          size="mini"
                          icon="el-icon-check"
                          type="primary"
                          @click="handleReception(scope.$index, scope.row)">接诊</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <!--设置分页-->
                <div class="block">
                  <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="this.queryParams.pageNum"
                    :page-sizes="[2, 3, 4, 5]"
                    :page-size="this.queryParams.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="this.queryParams.total">
                  </el-pagination>
                </div>
              </el-tab-pane>
              <el-tab-pane label="就诊中列表">
                <div id="reception-data">
                  <el-table
                    :data="tableData"
                    style="width: 100%">
                    <el-table-column type="expand">
                      <template slot-scope="props">
                        <el-form label-position="left" inline class="demo-table-expand">
                          <el-form-item label="患者姓名:">
                            <span>{{ props.row.kbjzPatient.patientName }}</span>
                          </el-form-item>
                          <el-form-item label="患者电话:">
                            <span>{{ props.row.kbjzPatient.patientPhone }}</span>
                          </el-form-item>
                          <el-form-item label="患者编号:">
                            <span>{{ props.row.kbjzPatient.patientId }}</span>
                          </el-form-item>
                          <el-form-item label="患者性别:">
                            <span>{{ props.row.kbjzPatient.patientSex }}</span>
                          </el-form-item>
                          <el-form-item label="患者年龄:">
                            <span>{{ props.row.kbjzPatient.patientAge }}</span>
                          </el-form-item>
                          <el-form-item label="地址信息:">
                            <span>{{ props.row.kbjzPatient.patientAddress }}</span>
                          </el-form-item>
                          <el-form-item label="过敏史:">
                            <span>{{ props.row.kbjzPatient.patientAllergy }}</span>
                          </el-form-item>
                        </el-form>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="患者姓名"
                      prop="kbjzPatient.patientName">
                    </el-table-column>

                    <el-table-column
                      label="流水编号"
                      prop="pipeNum">
                    </el-table-column>

                    <el-table-column
                      label="挂号类型"
                      prop="sysRegFee.rfeeName">
                    </el-table-column>

                    <el-table-column label="操作">
                      <template slot-scope="scope">
                        <el-button
                          size="mini"
                          icon="el-icon-check"
                          type="primary"
                          @click="handleReception(scope.$index, scope.row)">查看</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <!--设置分页-->
                <div class="block">
                  <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="this.queryParams.pageNum"
                    :page-sizes="[2, 3, 4, 5]"
                    :page-size="this.queryParams.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="this.queryParams.total">
                  </el-pagination>
                </div>
              </el-tab-pane>
              <el-tab-pane label="就诊完成列表">
                <div id="finish-reception-data">
                  <el-table
                    :data="tableData"
                    style="width: 100%">
                    <el-table-column type="expand">
                      <template slot-scope="props">
                        <el-form label-position="left" inline class="demo-table-expand">
                          <el-form-item label="患者姓名:">
                            <span>{{ props.row.kbjzPatient.patientName }}</span>
                          </el-form-item>
                          <el-form-item label="患者电话:">
                            <span>{{ props.row.kbjzPatient.patientPhone }}</span>
                          </el-form-item>
                          <el-form-item label="患者编号:">
                            <span>{{ props.row.kbjzPatient.patientId }}</span>
                          </el-form-item>
                          <el-form-item label="患者性别:">
                            <span>{{ props.row.kbjzPatient.patientSex }}</span>
                          </el-form-item>
                          <el-form-item label="患者年龄:">
                            <span>{{ props.row.kbjzPatient.patientAge }}</span>
                          </el-form-item>
                          <el-form-item label="地址信息:">
                            <span>{{ props.row.kbjzPatient.patientAddress }}</span>
                          </el-form-item>
                          <el-form-item label="过敏史:">
                            <span>{{ props.row.kbjzPatient.patientAllergy }}</span>
                          </el-form-item>
                        </el-form>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="患者姓名"
                      prop="kbjzPatient.patientName">
                    </el-table-column>

                    <el-table-column
                      label="流水编号"
                      prop="pipeNum">
                    </el-table-column>

                    <el-table-column
                      label="挂号类型"
                      prop="sysRegFee.rfeeName">
                    </el-table-column>

                    <el-table-column label="操作">
                      <template slot-scope="scope">
                        <el-button
                          size="mini"
                          icon="el-icon-check"
                          type="primary"
                          @click="handleReception(scope.$index, scope.row)">查看</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <!--设置分页-->
                <div class="block">
                  <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="this.queryParams.pageNum"
                    :page-sizes="[2, 3, 4, 5]"
                    :page-size="this.queryParams.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="this.queryParams.total">
                  </el-pagination>
                </div>
              </el-tab-pane>
            </el-tabs>
          </el-dialog>
      </div>

       <!--添加药用处方-->
      <div id="medicine-dialog">
        <el-dialog
          title="添加【药用】处方"
          :visible.sync="centerDialogVisible"
          width="50%"
          center>
          <div>
            <span style="float: right;" v-if="medicineList.drugPresPrice != undefined">药品处方金额{{medicineList.drugPresPrice}}&yen;</span>
          </div>
          <div style="text-align: left">
            <el-button type="primary" @click="addAndSure">确定添加</el-button>
          </div>

          <div id="medicine-table">
            <el-table
              ref="singleTable"
              :data="selectMedicTableData"
              tooltip-effect="dark"
              style="width: 100%"
              @current-change="handleMedicinesTableCurrentChange">
              <el-table-column
                type="index"
                width="50">
              </el-table-column>

              <el-table-column
                label="药品名称"
                show-overflow-tooltip
                >
                <template slot-scope="scope">{{ scope.row.drugName }}</template>
              </el-table-column>
              <el-table-column
                label="数量"
                min-width="110"
                show-overflow-tooltip
                >
                <template slot-scope="scope">
                     <el-input-number size="mini" :step="1"  v-model="scope.row.drugNum"   @change="handleDrugNumChange(scope.$index, scope.row)" :min="1" :max="scope.row.drugNumof" ></el-input-number>
                </template>
              </el-table-column>

              <el-table-column
                label="单价(元)"
                >
                <template slot-scope="scope">{{ scope.row.drugPrice}}</template>
              </el-table-column>

              <el-table-column
                label="金额(元)"
                width="80px"
                >
                <template slot-scope="scope">{{scope.row.drugPrice * scope.row.drugNum}}</template>
              </el-table-column>

              <el-table-column
                label="服用备注"
                width="120px"
                >
                <template slot-scope="scope">
                   <el-input size="mini" style="width: 110px" v-model="medicineList.remark" placeholder="照说明服用"></el-input>
                </template>
              </el-table-column>

              <el-table-column
                label="操作"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="danger"
                    @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <el-button style="width: 100%" type="primary" @click="medicDrawer= true">添加药品选项</el-button>
        </el-dialog>
      </div>

      <!--添加检查处方-->
      <div id="check-dialog">
        <el-dialog
          title="添加【检查】处方"
          :visible.sync="centerCheckDialogVisible"
          width="50%"
          center>
          <div>
            <span style="float: right;" v-if="medicineList.drugPresPrice != undefined">检查处方金额{{medicineList.drugPresPrice}}&yen;</span>
          </div>
          <div style="text-align: left">
            <el-button type="primary" @click="addAndSure">确定添加</el-button>
          </div>

          <div id="check-table">
            <el-table
              ref="singleTable"
              :data="selectCheckTableData"
              tooltip-effect="dark"
              style="width: 100%"
              @current-change="handleMedicinesTableCurrentChange">
              <el-table-column
                type="index"
                width="50">
              </el-table-column>

              <el-table-column
                label="项目名称"
                show-overflow-tooltip
              >
                <template slot-scope="scope">{{ scope.row.itemName }}</template>
              </el-table-column>
              <el-table-column
                label="单位"
                show-overflow-tooltip
              >
                <template slot-scope="scope">{{ scope.row.itemUnit}}</template>
              </el-table-column>

              <el-table-column
                label="单价(元)"
              >
                <template slot-scope="scope">{{ scope.row.itemPrice}}</template>
              </el-table-column>

              <el-table-column
                label="金额(元)"
                width="80px"
              >
                <template slot-scope="scope">{{ scope.row.itemPrice}}</template>
              </el-table-column>

              <el-table-column
                label="检查备注"
                width="120px"
              >
                <template slot-scope="scope">
                  <el-input size="mini" style="width: 110px" v-model="medicineList.checkRemark" placeholder="无"></el-input>
                </template>
              </el-table-column>

              <el-table-column
                label="操作"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="danger"
                    @click="handleCheckDelte(scope.$index, scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <el-button style="width: 100%" type="primary" @click="checkDrawer= true">添加检查选项</el-button>
        </el-dialog>
      </div>




      <div id="medDrawer">
        <el-drawer
          :visible.sync="medicDrawer"
          size="33%"
          direction="rtl"
          :before-close="handleClose">
          <div slot="title" style="font-size: 20px;text-align: center;color: #409EFF;" >药品列表</div>

          <!--关键字搜索-->
          <div>
            <el-form :inline="true" :model="medicineList" label-width="68px" class="demo-form-inline">
              <el-form-item label="关键字">
                <el-input v-model="medicineList.keyword" size="mini" placeholder="请输入药品关键字"></el-input>
              </el-form-item>

              <el-form-item>
                <el-button size="mini" type="primary" icon="el-icon-search" @click="onMedicSubmit">查询</el-button>
              </el-form-item>
              <el-form-item>
                <el-button size="mini" type="primary" icon="el-icon-refresh" @click="onMedicRest">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
          <div id="medicines-list">
            <el-table
              ref="multipleTable"
              :data="medicTableData"
              tooltip-effect="dark"
              style="width: 100%"
              @selection-change="handleSelectionChange">
              <el-table-column
                type="selection"
                width="55">
              </el-table-column>
              <el-table-column
                label="药品ID"
                width="120">
                <template slot-scope="scope">{{ scope.row.drugId }}</template>
              </el-table-column>
              <el-table-column
                label="药品名称"
                show-overflow-tooltip
                min-width="120">
                <template slot-scope="scope">{{ scope.row.drugName }}</template>
              </el-table-column>
              <el-table-column
                label="库存量"
                width="70px"
                show-overflow-tooltip>
                <template slot-scope="scope">{{ scope.row.drugNum}}</template>
              </el-table-column>

              <el-table-column
                label="单位"
                width="70px"
                show-overflow-tooltip>
                <template slot-scope="scope">{{ scope.row.drugUnit}}</template>
              </el-table-column>

              <el-table-column
                label="换算量"
                width="70"
                show-overflow-tooltip>
                 <template slot-scope="scope">{{ scope.row.drugNumof}}</template>
              </el-table-column>
            </el-table>
            <div style="margin-top: 20px;text-align: center" >
              <el-button type="primary" size="mini"  icon="el-icon-check" @click="addAndClose">添加并关闭</el-button>
              <el-button type="primary" size="mini"  icon="el-icon-refresh" @click="toggleSelection">取消选择</el-button>
            </div>
          </div>
        </el-drawer>
      </div>

        <div id="checkDrawer">
          <el-drawer
            :visible.sync="checkDrawer"
            size="33%"
            direction="rtl"
            :before-close="handleClose">
            <div slot="title" style="font-size: 20px;text-align: center;color: #409EFF;" >药品列表</div>

            <!--关键字搜索-->
            <div>
              <el-form :inline="true" :model="checkList" label-width="68px" class="demo-form-inline">
                <el-form-item label="关键字">
                  <el-input v-model="checkList.keyword" size="mini" placeholder="请输入关键字"></el-input>
                </el-form-item>

                <el-form-item>
                  <el-button size="mini" type="primary" icon="el-icon-search" @click="onCheckItemSubmit">查询</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button size="mini" type="primary" icon="el-icon-refresh" @click="onMedicRest">重置</el-button>
                </el-form-item>
              </el-form>
            </div>
            <div id="check-list">
              <el-table
                ref="multipleTable"
                :data="checkItemTableData"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange">
                <el-table-column
                  type="selection"
                  width="55">
                </el-table-column>
                <el-table-column
                  label="项目费用ID"
                  width="120">
                  <template slot-scope="scope">{{ scope.row.itemId }}</template>
                </el-table-column>
                <el-table-column
                  label="项目名称"
                  show-overflow-tooltip
                  min-width="120">
                  <template slot-scope="scope">{{ scope.row.itemName }}</template>
                </el-table-column>
                <el-table-column
                  label="关键字"
                  width="70px"
                  show-overflow-tooltip>
                  <template slot-scope="scope">{{ scope.row.itemKey}}</template>
                </el-table-column>

                <el-table-column
                  label="项目单价"
                  width="80px"
                  show-overflow-tooltip>
                  <template slot-scope="scope">{{ scope.row.itemPrice}}</template>
                </el-table-column>

                <el-table-column
                  label="单位"
                  width="60"
                  show-overflow-tooltip>
                  <template slot-scope="scope">{{ scope.row.itemUnit}}</template>
                </el-table-column>
              </el-table>
              <div style="margin-top: 20px;text-align: center" >
                <el-button type="primary" size="mini"  icon="el-icon-check" @click="addAndCloseCheck">添加并关闭</el-button>
                <el-button type="primary" size="mini"  icon="el-icon-refresh" @click="toggleSelection">取消选择</el-button>
              </div>
            </div>
          </el-drawer>
      </div>
    </div>
</template>

<script>
    import {selectRegisterByCondition} from "@/api/kbjz/ghlist";
    import {saveCase,selectCaseByPatientId,updateRegisterStatus,selectDrugByKeyWord,selectAllOrByConditions} from "@/api/kbjz/newtreate";
    export default {
        name: "index",
        data() {
            return {
                pformdata: {
                    patientCard:'',
                    patientName:'',
                    patientPhone:'',
                    patientSex:"0",
                    patientBirthday:'',
                    patientAge:'',
                    patientAddress:'',
                    patientAllergy:'',
                    patientId:"",
                    registerId:undefined,
                },
                /*表格数据*/
                tableData: [],
                dialogTableVisible: false,
                dialogFormVisible: false,
                /*表格病例*/
                tableCaseData:[],
                currentRow:undefined,//病例的当前行
                formLabelWidth: '120px',
                queryParams:{
                    pageNum:1,
                    pageSize:2,
                    total:undefined,
                    currentRow:undefined,
                    caseDate:undefined,
                    caseIsfect:undefined,
                    caseType:undefined,
                    caseMainsay:undefined,
                    caseDiagInfo:undefined,
                    caseAdvice:undefined,
                    caseRemark:undefined,
                    caseId:undefined,
                },
                activeName: 'first',
                activeTabName:"first",
                centerDialogVisible: false,
                /*药品设计到的数据*/
                medicineList:{
                    drugPresPrice:undefined,
                    keyword:undefined,
                    drugNum:[],
                    remark:"照说明服用",
                    checkRemark:"无",
                },
                checkList:{
                    keyword: "",
                },
                //存放选择的药品
                multipleSelection: [],
                //设置药品抽屉
                medicDrawer: false,
                checkDrawer:false,
                //药品表格数据
                medicTableData:[],
                /*选择的药品数据*/
                selectMedicTableData:[],
                num:1,
                centerCheckDialogVisible:false,
                checkItemTableData:[],
                selectCheckTableData:[],
            }
        },
        methods: {

            addAndSure(){
                this.centerDialogVisible = false;

                console.log(this.selectMedicTableData)
            },

            //处理删除数据
            handleDelete(index, row) {
                this.selectMedicTableData.pop(row);
            },
            handleCheckDelte(index,row){
                this.selectCheckTableData.pop(row);
            },
            /*添加和关闭抽屉的数据*/
            addAndCloseCheck: function () {
                var arr = new Array();
                if (this.multipleSelection == undefined){
                    this.$message({
                        message: '还未选择检查项目',
                        type: 'warning'
                    });
                    return;
                }
                for (var i = 0; i < this.multipleSelection.length; i++) {
                    var flag = false;
                    for (var j = 0;j < this.selectCheckTableData.length;j++){
                        if (this.selectCheckTableData[j].itemName == this.multipleSelection[i].itemName){
                            flag = true;
                            this.$message({
                                message: '药品已经选择过了，请重新选择新的商品',
                                type: 'warning'
                            });
                            break;
                        }
                    }
                    if (!flag){
                        arr.push(this.multipleSelection[i]);
                    }
                }
                this.selectCheckTableData = this.selectCheckTableData.concat(arr);

                this.multipleSelection =undefined;
                this.checkDrawer = false;
            },
            /*添加和关闭抽屉的数据*/
            addAndClose: function () {
                var arr = new Array();
                if (this.multipleSelection == undefined){
                    this.$message({
                        message: '还未选择药品',
                        type: 'warning'
                    });
                    return;
                }
                for (var i = 0; i < this.multipleSelection.length; i++) {
                    var flag = false;
                    for (var j = 0;j < this.selectMedicTableData.length;j++){
                        if (this.selectMedicTableData[j].drugName == this.multipleSelection[i].drugName){
                            flag = true;
                            this.$message({
                                message: '药品已经选择过了，请重新选择新的商品',
                                type: 'warning'
                            });
                            break;
                        }
                    }
                    if (!flag){
                        arr.push(this.multipleSelection[i]);
                    }
                }
                this.selectMedicTableData = this.selectMedicTableData.concat(arr);
                for (var j = 0;j < this.selectMedicTableData.length;j++){
                    this.selectMedicTableData[j].drugNumof = this.selectMedicTableData[j].drugNum;
                    this.selectMedicTableData[j].drugNum = 1;
                }
                this.medicDrawer = false;
            },
            onMedicRest(){
                this.medicineList.keyword == undefined;
            },
            /**
             * 通过关键字查询
             */
            onMedicSubmit() {
               if (this.medicineList.keyword == undefined){
                   this.$message({
                       message: '请输入关键字，再查询',
                       type: 'warning'
                   });
               }else{
                   selectDrugByKeyWord(this.medicineList.keyword).then(
                       res=>{
                           this.medicTableData = res.rows;
                       }
                   );
               }
            },
            onCheckItemSubmit(){
                  selectAllOrByConditions(this.checkList.keyword).then(
                      res=>{
                          this.checkItemTableData = res.rows;
                      }
                  );
            },
            selectPatients(){
                this.queryParams.registerStatus=1;
                this.queryParams.flag = true;
                selectRegisterByCondition(this.queryParams).then(
                    res=>{
                        this.tableData = res.rows;
                        this.queryParams.total =res.total;
                        this.queryParams.patientId = res.rows.patientId;
                    }
                );
                /*打开对话框*/
                this.dialogTableVisible = true;
            },
            /*每页显示的条数*/
            handleSizeChange(val) {
                this.queryParams.pageSize = val;
            },
            /*当前页*/
            handleCurrentChange(val){
                this.queryParams.total = val;
            },
            /*处理接诊*/
            handleReception(index, row) {
                this.pformdata = row.kbjzPatient;
                this.pformdata.patientSex = row.kbjzPatient.patientSex+'';
                this.pformdata.registerId = row.registerId;
                //log
                selectCaseByPatientId(this.pformdata.patientId).then(
                    res=>{
                        this.tableCaseData = res.rows;
                    }
                );
                //    关闭对话框
                this.dialogTableVisible = false;
            },
            handleReceptionClick(tab, event) {
                this.dialogTableVisible = true;
                this.queryParams.flag = true;
                if (tab.index == 0){
                    this.queryParams.registerStatus=1;
                }else if (tab.index == 1){
                    this.queryParams.registerStatus=3;
                }else if (tab.index == 2){
                    this.queryParams.registerStatus=4;
                }
                selectRegisterByCondition(this.queryParams).then(
                    res=>{
                        this.tableData = res.rows;
                        this.queryParams.total =res.total;
                    }
                );
            },
            handleInfoClick(tab, event) {
                console.log(tab, event);
            },
            /*保存病例*/
            saveCase(){
                if (this.pformdata.patientId != null && this.pformdata.patientId !='' && this.queryParams.caseId == ''){
                    this.queryParams.patientId = this.pformdata.patientId;
                    this.queryParams.registerId = this.pformdata.registerId;
                    saveCase(this.queryParams).then(
                        res =>{
                            this.queryParams.caseId = res.data;
                            this.$message({
                                message:res.message,
                                type: 'warning'
                            });
                        }
                    );
                }else if (this.pformdata.patientId == null || this.pformdata.patientId =='' ){
                    this.$message({
                        message: '请先选择患者，再保存病例',
                        type: 'warning'
                    });
                }else{
                    this.$message({
                        message: '已保存的病例无法修改',
                        type: 'warning'
                    });
                }

            },
            /*接诊完成按钮*/
            finshcase(){
                if (this.pformdata.registerId != '' && this.pformdata.registerId != undefined){
                    this.pformdata.registerStatus = 4;
                    updateRegisterStatus(this.pformdata).then(
                        res=>{
                            if (res.code == 200){
                                this.$message({
                                    message: '接诊完成',
                                    type: 'warning'
                                });
                            }else{
                                this.$message({
                                    message: res.message,
                                    type: 'warning'
                                });
                            }
                        }
                    );
                }else{
                    this.$message({
                        message: '请先选择患者,接诊完成之后，再点击接诊完成按钮',
                        type: 'warning'
                    });
                }

            },
            setCurrent(row) {
               // this.$refs.singleTable.setCurrentRow(row);
            },
            handleCurrentChange(val) {
                this.currentRow = val;
                this.queryParams = val;
            },
            setCurrent(row) {
                this.$refs.singleTable.setCurrentRow(row);
            },
            handleMedicinesTableCurrentChange(val) {
                this.currentRow = val;
            },
            /*处理关闭抽屉的方法*/
            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => {});
            },
            /*处理药品被选中*/
            toggleSelection(rows) {
               /*取消选择*/

                this.$refs.multipleTable.clearSelection();

            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style scoped>
  #patient-form,#title-header,#case-main{
    width: 100%;
    padding: 10px;
    box-shadow: 1px 1px 4px 4px #EBEEF5;
    margin: 0px;
  }
  #title-header{
    margin-top: 10px;
  }
  #layout,#con{
    height: 630px;
  }
  .el-aside {
    background-color: white;
    text-align: center;
  }




  /*设置输入框的长度*/
  .input-width{
    width: 200px;
  }
  .el-form-item{
    margin-bottom: 10px;
  }
</style>
